//
//  BaseObject.swift
//  MyWeiBo
//
//  Created by mac on 15/3/2.
//  Copyright (c) 2015年 gpr. All rights reserved.
//

import UIKit
//import JSONModel

class BaseObject: NSObject {
    
    class func objectWithJSONData(data: NSData) -> AnyObject {
        let dict: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.allZeros, error: nil)
        return self.objectWithDictionary(dict as! [String :AnyObject])
    }
    
    ///  通过一个字典来构建一个模型
    ///
    ///  :param: dictionary 字典
    ///
    ///  :returns: 模型实例
    class func objectWithDictionary(dictionary: [String :AnyObject]) -> AnyObject {
        return JSONModelSerializer.shareInstance.objectWithDictionary(dictionary, modelClass: self)
    }
    
    ///  模型转字典
    ///
    ///  :returns: 字典
    func dictionaryFromSelf() -> [String: AnyObject] {
        return JSONModelSerializer.shareInstance.dictionaryWithObject(self)
    }
    
}


